<?php
/**
 * 公共常量
 */
namespace App\Models\CacheDb\Order;

use App\Models\CacheDb\CommonModel;
use App\Models\ConstCode;

class RealTimePayCache extends CommonModel {

    protected $table;
    protected $cache_key = 'RealTimePayCache';
    protected $second = 3600*24;

    public function __construct($order_sn){
        $this->table = $this->cache_key.'_'.$order_sn;
    }

    /**
     * 获取订单实时支付状态
     * @param $order_sn
     * @return array
     */
    static public function getStatus($order_sn){
        $cache = new self($order_sn);
        $result = $cache->getValue();
        if(empty($result)){
            $result = [
                'status'=>ConstCode::REAL_TIME_PAY_WAIT,
                'time'=>NOW_TIME,
            ];
        }
        return $result;
    }

    /**
     * 设置订单实时支付状态
     * @param $order_sn
     * @return bool
     */
    static public function setStatus($order_sn,$status){
        $cache = new self($order_sn);
        $result = [
            'status'=>$status,
            'time'=>NOW_TIME,
        ];
        return $cache->setValue($result);
    }

}
